$(function() {
	// ͳ�Ƶ�ְλ�������Դ�ű� add by Vee ��2014-7-3
	// $('#jobList a').click(function(e){
	// e.preventDefault();
	// var href=$(this).attr("href");
	// window.location.href=href+"?source=company"; //��˾����ҳ
	// });
	// end
	// Ҫ����ְλ��ʾ
	$('.tipExpire .expire_close').bind('click', function() {
		var count = $.cookie('showExpriedCompanyHome');
		$.cookie('showExpriedCompanyHome', count - 1);
		$(this).parent('.tipExpire').hide();
	});

	/***************************************************************************
	 * B & C �� ��˾����ҳ
	 * 
	 * ȡ��༭��˾��ǩ
	 */

	// $.cookie('labels', $('#hasLabels').html());
	/* nancy add companyLabels */
	var companyLabels = $('#hasLabels').html();
	$('#cancelLabels').click(function() {
		/* add nancy */
		$('#label').val('');
		$('#addLabels').hide();
		$('.c_box h3').hide();
		$('#hasLabels li').each(function() {
			$(this).find('i').remove();
		});
		$('#hasLabels').on('mouseenter', 'li', function() {
			$(this).css({
				marginRight : '18px',
				cursor : 'default'
			});
		});
		$('#hasLabels').append('<li class="link">�༭</li>');
		$('#hasLabels').empty().append(companyLabels);
		$(this).parents('.c_detail').removeClass('c_detail_bg');
	});
	/***************************************************************************
	 * ����༭��˾��ǩ
	 */
	$('#saveLabels').click(function() {
		/** add nancy* */
		if ($.trim($('#label')).length !== 0) {
			$('#label').val('');
		}
		/** end nancy* */
		var labels = [];
		var _this = $(this);
		$('#hasLabels li').each(function() {
			labels.push($(this).children('span').text());
		});
		var companyId = $('#companyId').val();
		$.ajax({
			type : 'POST',
			data : {
				companyId : companyId,
				labels : labels.join()
			},
			url : ctx + '/companyLabel/pasteLabelToCompany.json'
		}).done(function(result) {
			// console.log(result);
			if (result.success) {
				$('#addLabels').hide();
				$('.c_box h3').hide();
				$('#hasLabels li').each(function() {
					$(this).find('i').remove();
				});
				$('#hasLabels').on('mouseenter', 'li', function() {
					$(this).css({
						marginRight : '18px',
						cursor : 'default'
					});
				});
				$('#hasLabels').append('<li class="link">�༭</li>');
				companyLabels = $('#hasLabels').html();
				_this.parents('.c_detail').removeClass('c_detail_bg');
			} else {
				alert("����ʧ��");
			}
		});
	});
	/***************************************************************************
	 * �༭��ǩ
	 */
	$('#hasLabels').on(
			'click',
			'.link',
			function() {
				/** add nancy* */
				// �ж�IE������汾
				if (navigator.userAgent.indexOf("MSIE") > 0) {
					if (navigator.userAgent.indexOf("MSIE 7.0") > 0
							|| navigator.userAgent.indexOf("MSIE 8.0") > 0
							|| navigator.userAgent.indexOf("MSIE 9.0") > 0) {
						var placeholder = $('#label').attr('placeholder');
						$('#label').val(placeholder).css('color', '#777777');
					}
				}

				$('#changeLabels').trigger('click');
				$('.c_detail').addClass('c_detail_bg');
				$('#addLabels').show();
				$('.c_box h3').show();
				$(this).remove();
				$('#hasLabels li').each(function() {
					$(this).append('<i>x</i>');
				});

				$('#hasLabels').on('mouseenter', 'li', function() {
					$(this).css({
						marginRight : '6px',
						cursor : 'pointer'
					});
				});
				$('#hasLabels').on('mouseleave', 'li', function() {
					$(this).css({
						marginRight : '18px',
						cursor : 'pointer'
					});
				});
			});

	/***************************************************************************
	 * ɾ��ǩ
	 */
	$('#hasLabels').on('click', 'li i', function() {
		$(this).parent().remove();
		/*
		 * var labelVal = $(this).prev('span').text(); var _this = $(this); var
		 * companyId = $('#companyId').val(); $.ajax({ type:'post', url:
		 * ctx+'/companyLabel/removeOneLabelToCompany.json',
		 * data:{companyId:companyId,label:labelVal}, dataType: 'json'
		 * }).success(function (result) { if(result.success){
		 * _this.parent().remove(); }else{ alert(result.msg); } });
		 */
	});

	/***************************************************************************
	 * ѡ��ǩ
	 */
	$('#addLabels ul').on(
			'click',
			'li',
			function() {
				/*
				 * if(!$(this).hasClass('curr')){ $(this).addClass('curr'); var
				 * labelVal = $(this).text(); var judge = true; $('#hasLabels
				 * li').each(function(){ if($(this).children('span').text() ==
				 * labelVal){ alert("�˱�ǩ�Ѵ��ڣ�����������"); judge = false; } });
				 * if(judge){ $('#hasLabels').append('<li><span>'+labelVal+'</span><i>x</i></li>'); } }
				 */
				/** add nancy* */
				var judge = true;
				var labelVal = $(this).text();
				if (!$(this).hasClass('curr')) {
					$(this).addClass('curr');
					$('#hasLabels li').each(function() {
						if ($(this).children('span').text() == labelVal) {
							judge = false;
							return judge;
						}
					});
				} else {
					$('#hasLabels li').each(function() {
						if ($(this).children('span').text() == labelVal) {
							judge = false;
							return judge;
						}
					});
				}
				if (judge) {
					$('#hasLabels').append(
							'<li><span>' + labelVal + '</span><i>x</i></li>');
				} else {
					alert("�˱�ǩ�Ѵ��ڣ�����������");
				}
				/** end nancy* */
			});

	/***************************************************************************
	 * ���ǩ
	 */
	$('#add_label').bind(
			'click',
			function() {
				var _label = $('#label');
				var labelVal = $.trim(_label.val());
				var judge = true;
				if (labelVal.length <= 6 && labelVal.length > 0) {
					$('#hasLabels li').each(function() {
						if ($('span', this).text() == labelVal) {
							judge = false;
						}
					});
					if (judge) {
						$('#hasLabels').append(
								'<li><span>' + labelVal
										+ '</span><i>x</i></li>');
					} else {
						alert('�˱�ǩ�Ѵ��ڣ�����������');
					}
					_label.val('');
				} else {
					alert("������1-6�ֵ��Զ����ǩ");
					/* alert("������1-6���ֵĹ�˾��ǩ"); */
				}
			});

	/***************************************************************************
	 * enter�����ǩ
	 */
	$('#label').keydown(function(e) {
		if (e.which == 13) {
			$('#add_label').trigger('click');
		}
	});

	/***************************************************************************
	 * ��ǩ��һ��
	 */
	var pageNo = 1;
	$('#changeLabels').click(function() {
		$.ajax({
			type : 'POST',
			url : ctx + '/companyLabel/changeLabels.json',
			data : {
				pageNo : pageNo,
				pageSize : 12
			}
		}).done(function(result) {
			if (result != '') {
				var str = '';
				for ( var label in result.content) {
					str += '<li>' + result.content[label] + '</li>';
				}
				;
				$('#addLabels ul').html(str);
			} else {
				alert("����ʧ��");
			}
		});
		pageNo++;
	}); // end #changeLabels

	/***************************************************************************
	 * ��˾��Ʒչʾ��������ʽ
	 */
	$('.scroll-pane').jScrollPane();

	/***************************************************************************
	 * B �� ��˾����ҳ �ɱ༭
	 * 
	 * ��Ӵ�ʼ�� �༭��ʼ�� ɾ��ʼ��
	 */
	$('#Member')
			.on(
					"click",
					".c_add",
					function() {
						if ($("#Member .member_wrap").length < 3) {
							var memberWrap = $(this).parents('#Member').find(
									".member_wrap").first().clone();

							$(".member_info:nth-child(1)", memberWrap)
									.addClass("dn");
							$(
									".member_info:nth-child(2) input[type!='submit'],.member_info:nth-child(2) textarea",
									memberWrap).val("");
							$(".member_info:nth-child(2) .word_count",
									memberWrap).children('span').text(500);
							$(".member_info:nth-child(2) img", memberWrap)
									.attr("src", "");
							$(".member_info:nth-child(2) .portraitShow",
									memberWrap).hide();
							$(".member_info:nth-child(2) .portraitNo",
									memberWrap).show();
							$(".member_info:nth-child(2)", memberWrap)
									.removeClass("dn");
							$(".member_info:nth-child(3)", memberWrap)
									.addClass("dn");
							$(memberWrap).appendTo("#Member dd");

							$("#Member .member_wrap").each(
									function(i) {
										$(this).find("input[type='file']")
												.attr("id", "profiles" + i);
									});
						}

						if ($("#Member .member_wrap").length >= 3) {
							$("#Member .c_add").hide();
						}

						$('.memberForm', memberWrap)
								.validate(
										{
											// onkeyup: false,
											// focusCleanup:true,
											// onfocusout:false,
											// onsubmit:true,
											rules : {
												myfiles : {
													required : false
												},
												name : {
													required : false,
													specialchar : true,
													checkNum : true,
													rangeLenStr : [ 1, 10 ]
												},
												position : {
													required : false,
													specialchar : true,
													checkNum : true,
													maxlenStr : 30
												},
												weibo : {
													required : false,
													checkUrlNot : true,
													maxlength : 80
												},
												remark : {
													/*
													 * required:false,
													 * minlength: 10,
													 * maxlength:500
													 */
													required : false,
													checkNum : true,
													rangeLenStr : [ 10, 500 ]
												}
											},
											messages : {
												name : {
													specialchar : "��������ʵ�Ĵ�ʼ������",
													checkNum : "��������ʵ�Ĵ�ʼ������",
													rangeLenStr : "��������ʵ�Ĵ�ʼ������"
												},
												position : {
													specialchar : "��������ʵ�ĵ�ǰְλ",
													checkNum : "��������ʵ�ĵ�ǰְλ",
													maxlenStr : "��������ʵ�ĵ�ǰְλ"
												},
												weibo : {
													checkUrlNot : "��������ʵ������΢����ַ",
													maxlength : "������80�ַ����ڵ���ַ"
												},
												remark : {
													/*
													 * minlength:"������10-500�ֵĸ��˼��",
													 * maxlength:"������10-500�ֵĸ��˼��"
													 */
													checkNum : "��������Ч�ĸ��˼��",
													rangeLenStr : "������10-500�ֵĸ��˼��"
												}
											},
											submitHandler : function(form) {
												var companyId = $('#companyId')
														.val();
												var leaderId = $('.leader_id',
														form).val();
												var photo = $('.leaderInfos',
														form).val();
												var name = $(
														'input[name="name"]',
														form).val() != '�����봴ʼ������' ? $(
														'input[name="name"]',
														form).val()
														: '';
												var position = $(
														'input[name="position"]',
														form).val() != '�����봴ʼ�˵�ǰְλ' ? $(
														'input[name="position"]',
														form).val()
														: '';
												var weibo = $.trim($(
														'input[name="weibo"]',
														form).val()) != '�����봴ʼ������΢����ַ' ? $
														.trim($(
																'input[name="weibo"]',
																form).val())
														: '';
												if (weibo != ''
														&& weibo
																.substring(0, 7) != 'http://') {
													weibo = 'http://' + weibo;
												}
												var remark = $(
														'textarea[name="remark"]',
														form).val() != '�����봴ʼ�˸��˼��' ? $(
														'textarea[name="remark"]',
														form).val()
														: '';
												var resubmitToken = $(
														'#resubmitToken').val();
												memberWrap = $(form).parents(
														".member_wrap");
												$(form).find(":submit").attr(
														"disabled", true);
												$
														.ajax(
																{
																	type : 'POST',
																	url : ctx
																			+ '/cl/saveLeaderInfo.json',
																	data : {
																		companyId : companyId,
																		id : leaderId,
																		photo : photo,
																		name : name,
																		position : position,
																		weibo : weibo,
																		remark : remark,
																		resubmitToken : resubmitToken
																	},
																	dataType : 'json'
																})
														.success(
																function(result) {
																	if (null != result.resubmitToken
																			&& '' != result.resubmitToken) {
																		$(
																				'#resubmitToken')
																				.val(
																						result.resubmitToken);
																	}
																	if (result.success) {
																		$(
																				".member_info:nth-child(1)",
																				memberWrap)
																				.addClass(
																						"dn");

																		$(
																				".member_info:nth-child(2)",
																				memberWrap)
																				.addClass(
																						"dn");
																		$(
																				".member_info:nth-child(2) .leader_id",
																				memberWrap)
																				.val(
																						result.content.id);

																		$(
																				".member_info:nth-child(3) img",
																				memberWrap)
																				.attr(
																						"src",
																						ctx
																								+ '/'
																								+ result.content.photo);
																		if (result.content.weibo != '') {
																			$(
																					".member_info:nth-child(3) .m_name",
																					memberWrap)
																					.html(
																							result.content.name
																									+ '<a href="'
																									+ result.content.weibo
																									+ '" class="weibo" target="_blank"></a>');
																		} else {
																			$(
																					".member_info:nth-child(3) .m_name",
																					memberWrap)
																					.html(
																							result.content.name);
																		}
																		$(
																				".member_info:nth-child(3) .m_position",
																				memberWrap)
																				.html(
																						result.content.position);
																		$(
																				".member_info:nth-child(3) .m_intro",
																				memberWrap)
																				.html(
																						result.content.remark);
																		$(
																				".member_info:nth-child(3)",
																				memberWrap)
																				.removeClass(
																						"dn");
																		if ($("#Member .member_wrap").length >= 3) {
																			$(
																					"#Member .c_add")
																					.hide();
																		} else {
																			$(
																					"#Member .c_add")
																					.show();
																		}
																	} else {
																		if ($('.member_wrap').length == 1) {
																			$(
																					".member_info:nth-child(1)",
																					memberWrap)
																					.removeClass(
																							"dn");
																			$(
																					".member_info:nth-child(2)",
																					memberWrap)
																					.addClass(
																							"dn");
																			$(
																					".member_info:nth-child(2) input[type!='submit'], .member_info:nth-child(2) textarea",
																					memberWrap)
																					.val(
																							"");
																			$(
																					".member_info:nth-child(3)",
																					memberWrap)
																					.addClass(
																							"dn");
																			$(
																					"#Member .c_add")
																					.hide();
																		} else {
																			$(
																					memberWrap)
																					.remove();
																			$(
																					"#Member .c_add")
																					.show();
																		}
																	}
																	$(form)
																			.find(
																					":submit")
																			.attr(
																					"disabled",
																					false);
																});
											}
										});
					});

	$('#Member').on(
			"click",
			".member_edit",
			function() {
				// add nancy
				$('.newMember .memberForm span.error').hide();
				// end nancy
				var memberWrap = $(this).parents(".member_wrap");
				var m_intro = $(".member_info:nth-child(3) .m_intro",
						memberWrap).html();
				if (m_intro) {
					m_intro = $.trim(m_intro.replace(/<br>/gi, ''));
				}
				$(".member_info:nth-child(2) textarea", memberWrap)
						.val(m_intro);
				$(".member_info:nth-child(2) .word_count", memberWrap)
						.children('span').text(
								500 - $(".member_info:nth-child(2) textarea",
										memberWrap).val().length);
				$(".member_info:nth-child(2)", memberWrap).removeClass("dn");
				$(".member_info:nth-child(1)", memberWrap).addClass("dn");
				$(".member_info:nth-child(3)", memberWrap).addClass("dn");
			});

	$('#Member')
			.on(
					"click",
					".member_delete",
					function() {
						if (confirm('ȷ��Ҫɾ��ô�ʼ����')) {
							var leaderId = $(this).next().val();
							var memberWrap = $(this).parents(".member_wrap");
							if (leaderId == "") {
								if ($("#Member .member_wrap").length <= 1) {
									$(".member_info:nth-child(1)", memberWrap)
											.removeClass("dn");
									$(".member_info:nth-child(2)", memberWrap)
											.addClass("dn");
									$(
											".member_info:nth-child(2) input[type!='submit'], .member_info:nth-child(2) textarea",
											memberWrap).val("");
									$(".member_info:nth-child(2) img",
											memberWrap).attr("src", "");
									$(
											".member_info:nth-child(2) .portraitShow",
											memberWrap).hide();
									$(".member_info:nth-child(2) .portraitNo",
											memberWrap).show();
									$(".member_info:nth-child(3)", memberWrap)
											.addClass("dn");
									$("#Member .c_add").hide();
								} else {
									$(memberWrap).remove();
									$("#Member .c_add").show();
								}
							} else {
								$
										.ajax(
												{
													type : 'POST',
													url : ctx
															+ '/cl/delLeaderInfo.json',
													data : {
														leaderId : leaderId
													},
													dataType : 'json'
												})
										.success(
												function(result) {
													if ($("#Member .member_wrap").length <= 1) {
														$(
																".member_info:nth-child(1)",
																memberWrap)
																.removeClass(
																		"dn");
														$(
																".member_info:nth-child(2)",
																memberWrap)
																.addClass("dn");
														$(
																".member_info:nth-child(2) input[type!='submit'], .member_info:nth-child(2) textarea",
																memberWrap)
																.val("");
														$(
																".member_info:nth-child(2) img",
																memberWrap)
																.attr("src", "");
														$(
																".member_info:nth-child(2) .portraitShow",
																memberWrap)
																.hide();
														$(
																".member_info:nth-child(2) .portraitNo",
																memberWrap)
																.show();
														$(
																".member_info:nth-child(3)",
																memberWrap)
																.addClass("dn");
														$("#Member .c_add")
																.hide();
													} else {
														$(memberWrap).remove();
														$("#Member .c_add")
																.show();
													}

													$("#Member .member_wrap")
															.each(
																	function(i) {
																		$(this)
																				.find(
																						"input[type='file']")
																				.attr(
																						"id",
																						"profiles"
																								+ i);
																	});

												});
							}
						}
					});

	// countdown
	/* $('#Member .memberForm').on('keyup','.s_textarea',function(){ */
	/** edit nancy* */
	$('#Member').on(
			'keyup',
			'.memberForm .s_textarea',
			function() {
				// textCounter('productProfile', '', 500);
				var field = $(this);
				/*
				 * if (field.val().length > 500) {
				 * field.val(field.val().substring(0, 500)); } else {
				 * field.next('.word_count').children('span').text(500 -
				 * field.val().length); }
				 */
				/** add nancy* */
				var len = $.trim(field.val()).length;
				if (len > 500) {
					field.val(field.val().substring(0, 500));
				} else if ($(this).siblings('span').length > 0
						&& (len > 10 || len == 10)) {
					$(this).siblings('span').hide();
				} else if ($(this).siblings('span').length > 0 && len < 10) {
					$(this).siblings('span').show();
				} else {
					field.next('.word_count').children('span').text(500 - len);
				}
				/** end nancy* */
			});

	/***************************************************************************
	 * ��Ӵ�ʼ����֤
	 */
	$('.memberForm')
			.each(
					function() {

						$(this)
								.validate(
										{
											onkeyup : false,
											// focusCleanup:true,
											/*
											 * rules: { myfiles: { required:
											 * false }, name:{ required:false },
											 * position:{ required:false },
											 * weibo: { required:false,
											 * checkUrlNot:true, maxlength:80 },
											 * remark: { required:false,
											 * minlength: 10, maxlength:500 } },
											 * messages: { weibo: {
											 * checkUrlNot:"��������ʵ������΢����ַ",
											 * maxlength:"������80�ַ����ڵ���ַ" },
											 * remark: {
											 * minlength:"������10-500�ֵĸ��˼��",
											 * maxlength:"������10-500�ֵĸ��˼��" } }
											 */
											rules : {
												myfiles : {
													required : false
												},
												name : {
													/* required:false */
													required : false,
													specialchar : true,
													checkNum : true,
													maxlenStr : 10
												},
												position : {
													required : false,
													specialchar : true,
													checkNum : true,
													maxlenStr : 30
												},
												weibo : {
													required : false,
													checkUrlNot : true,
													maxlength : 80
												},
												remark : {
													/*
													 * required:false,
													 * minlength: 10,
													 * maxlength:500
													 */
													required : false,
													checkNum : true,
													maxlenStr : 500
												}
											},
											messages : {
												name : {
													specialchar : "��������ʵ�Ĵ�ʼ������",
													checkNum : "��������ʵ�Ĵ�ʼ������",
													maxlenStr : "��������ʵ�Ĵ�ʼ������"
												},
												position : {
													specialchar : "��������ʵ�ĵ�ǰְλ",
													checkNum : "��������ʵ�ĵ�ǰְλ",
													maxlenStr : "��������ʵ�ĵ�ǰְλ"
												},
												weibo : {
													checkUrlNot : "��������ʵ������΢����ַ",
													maxlength : "������80�ַ����ڵ���ַ"
												},
												remark : {
													/*
													 * minlength:"������10-500�ֵĸ��˼��",
													 * maxlength:"������10-500�ֵĸ��˼��"
													 */
													checkNum : "��������Ч�ĸ��˼��",
													maxlenStr : "������10-500�ֵĸ��˼��"
												}
											},
											submitHandler : function(form) {
												var companyId = $('#companyId')
														.val();
												var leaderId = $('.leader_id',
														form).val();
												var photo = $('.leaderInfos',
														form).val();
												var name = $(
														'input[name="name"]',
														form).val() != '�����봴ʼ������' ? $(
														'input[name="name"]',
														form).val()
														: '';
												var position = $(
														'input[name="position"]',
														form).val() != '�����봴ʼ�˵�ǰְλ' ? $(
														'input[name="position"]',
														form).val()
														: '';
												var weibo = $.trim($(
														'input[name="weibo"]',
														form).val()) != '�����봴ʼ������΢����ַ' ? $
														.trim($(
																'input[name="weibo"]',
																form).val())
														: '';
												if (weibo != ''
														&& weibo
																.substring(0, 7) != 'http://') {
													weibo = 'http://' + weibo;
												}
												var remark = $(
														'textarea[name="remark"]',
														form).val() != '�����봴ʼ�˸��˼��' ? $(
														'textarea[name="remark"]',
														form).val()
														: '';
												var memberWrap = $(form)
														.parents(".member_wrap");
												var resubmitToken = $(
														'#resubmitToken').val();
												$(form).find(":submit").attr(
														"disabled", true);
												$
														.ajax(
																{
																	type : 'POST',
																	url : ctx
																			+ '/cl/saveLeaderInfo.json',
																	data : {
																		companyId : companyId,
																		id : leaderId,
																		photo : photo,
																		name : name,
																		position : position,
																		weibo : weibo,
																		remark : remark,
																		resubmitToken : resubmitToken
																	},
																	dataType : 'json'
																})
														.success(
																function(result) {
																	if (null != result.resubmitToken
																			&& '' != result.resubmitToken) {
																		$(
																				'#resubmitToken')
																				.val(
																						result.resubmitToken);
																	}
																	if (result.success) {
																		$(
																				".member_info:nth-child(1)",
																				memberWrap)
																				.addClass(
																						"dn");

																		$(
																				".member_info:nth-child(2)",
																				memberWrap)
																				.addClass(
																						"dn");
																		$(
																				".member_info:nth-child(2) .leader_id",
																				memberWrap)
																				.val(
																						result.content.id);

																		$(
																				".member_info:nth-child(3) img",
																				memberWrap)
																				.attr(
																						"src",
																						ctx
																								+ '/'
																								+ result.content.photo);
																		if (result.content.weibo != '') {
																			$(
																					".member_info:nth-child(3) .m_name",
																					memberWrap)
																					.html(
																							result.content.name
																									+ '<a href="'
																									+ result.content.weibo
																									+ '" class="weibo" target="_blank"></a>');
																		} else {
																			$(
																					".member_info:nth-child(3) .m_name",
																					memberWrap)
																					.html(
																							result.content.name);
																		}
																		$(
																				".member_info:nth-child(3) .m_position",
																				memberWrap)
																				.html(
																						result.content.position);
																		$(
																				".member_info:nth-child(3) .m_intro",
																				memberWrap)
																				.html(
																						result.content.remark);
																		$(
																				".member_info:nth-child(3)",
																				memberWrap)
																				.removeClass(
																						"dn");
																		if ($("#Member .member_wrap").length >= 3) {
																			$(
																					"#Member .c_add")
																					.hide();
																		} else {
																			$(
																					"#Member .c_add")
																					.show();
																		}
																	} else {
																		if ($('.member_wrap').length == 1) {
																			$(
																					".member_info:nth-child(1)",
																					memberWrap)
																					.removeClass(
																							"dn");
																			$(
																					".member_info:nth-child(2)",
																					memberWrap)
																					.addClass(
																							"dn");
																			$(
																					".member_info:nth-child(2) input[type!='submit'], .member_info:nth-child(2) textarea",
																					memberWrap)
																					.val(
																							"");
																			$(
																					".member_info:nth-child(3)",
																					memberWrap)
																					.addClass(
																							"dn");
																			$(
																					"#Member .c_add")
																					.hide();
																		} else {
																			$(
																					memberWrap)
																					.remove();
																			$(
																					"#Member .c_add")
																					.show();
																		}
																	}
																	$(form)
																			.find(
																					":submit")
																			.attr(
																					"disabled",
																					false);
																});
											}
										});

					});

	/***************************************************************************
	 * ��Ӳ�Ʒ �༭��Ʒ ɾ���Ʒ
	 */
	$('#Product')
			.on(
					"click",
					".product_add",
					function() {
						if ($("#Product .product_wrap").length < 3) {
							var productWrap = $(this).parents(".product_wrap")
									.clone();

							$("dl:nth-child(1)", productWrap).addClass("dn");
							$(
									"dl:nth-child(2) input[type!='submit'],dl:nth-child(2) textarea",
									productWrap).val("");
							$("dl:nth-child(2) .word_count", productWrap)
									.children('span').text(500);
							$("dl:nth-child(2) .productShow img", productWrap)
									.attr("src", "");
							$("dl:nth-child(2) .productShow", productWrap)
									.hide();
							$("dl:nth-child(2) .productNo", productWrap).show();
							$("dl:nth-child(2)", productWrap).removeClass("dn");
							$("dl:nth-child(3)", productWrap).addClass("dn");
							$(productWrap).appendTo("#Product");

							$("#Product .product_wrap").each(
									function(i) {
										$("input[type='file']", this).attr(
												"id", "myfiles" + i);
									});
						}

						if ($("#Product .product_wrap").length >= 3) {
							$(".product_add").addClass("dn");
						}
						$('.productForm', productWrap)
								.validate(
										{
											onkeyup : false,
											// focusCleanup:true,
											onfocusout : false,
											onsubmit : true,
											rules : {
												myfiles : {
													required : false
												},
												product : {
													required : false,
													checkNum : true,
													specialchar : true,
													/* maxlenStr:10 */
													rangeLenStr : [ 1, 10 ]
												},
												productUrl : {
													required : false,
													checkUrlNot : true,
													maxlength : 120
												},
												productProfile : {
													required : false,
													/*
													 * minlength: 10,
													 * maxlength:500
													 */
													checkNum : true,
													specialchar : true,
													rangeLenStr : [ 10, 500 ]
												}
											},
											messages : {
												product : {
													checkNum : "��������Ч�Ĳ�Ʒ���",
													specialchar : "��������Ч�Ĳ�Ʒ���",
													rangeLenStr : "������1-10�ֵĲ�Ʒ���"
												},
												productUrl : {
													checkUrlNot : "��������Ч�Ĳ�Ʒ��ҳ���Ʒ���ص�ַ",
													maxlength : "������120�ַ����ڵ���ַ"
												},
												productProfile : {
													/*
													 * minlength:"������10-500�ֵĲ�Ʒ���",
													 * maxlength:"������10-500�ֵĲ�Ʒ���"
													 */
													checkNum : "��������Ч�Ĳ�Ʒ���",
													specialchar : "��������Ч�Ĳ�Ʒ���",
													rangeLenStr : "������10-500�ֵĲ�Ʒ���"
												}
											},
											submitHandler : function(form) {
												var companyId = $('#companyId')
														.val();
												var productId = $(
														'.product_id', form)
														.val();
												var productPicUrl = $(
														'.productInfos', form)
														.val();
												var product = $(
														'input[name="product"]',
														form).val() != '�������Ʒ���' ? $(
														'input[name="product"]',
														form).val()
														: '';
												var productUrl = $
														.trim($(
																'input[name="productUrl"]',
																form).val()) != '�������Ʒ��ַ' ? $
														.trim($(
																'input[name="productUrl"]',
																form).val())
														: '';
												if (productUrl != ''
														&& productUrl
																.substring(0, 7) != 'http://') {
													productUrl = 'http://'
															+ productUrl;
												}
												var productProfile = $(
														'textarea[name="productProfile"]',
														form).val() != '���������ò�Ʒ��λ����Ʒ��ɫ���û�Ⱥ���' ? $(
														'textarea[name="productProfile"]',
														form).val()
														: '';
												var resubmitToken = $(
														'#resubmitToken').val();
												productWrap = $(form).parents(
														".product_wrap");
												$(form).find(":submit").attr(
														"disabled", true);
												$
														.ajax(
																{
																	type : 'POST',
																	url : ctx
																			+ '/cp/saveCompanyProduct.json',
																	data : {
																		companyId : companyId,
																		id : productId,
																		type : 1,
																		productPicUrl : productPicUrl,
																		product : product,
																		productUrl : productUrl,
																		productProfile : productProfile,
																		resubmitToken : resubmitToken
																	},
																	dataType : 'json'
																})
														.success(
																function(result) {
																	if (null != result.resubmitToken
																			&& '' != result.resubmitToken) {
																		$(
																				'#resubmitToken')
																				.val(
																						result.resubmitToken);
																	}
																	if (result.success) {
																		$(
																				"dl:nth-child(1)",
																				productWrap)
																				.addClass(
																						"dn");

																		$(
																				"dl:nth-child(2)",
																				productWrap)
																				.addClass(
																						"dn");
																		$(
																				"dl:nth-child(2) .product_id",
																				productWrap)
																				.val(
																						result.content.id);

																		$(
																				"dl:nth-child(3) img",
																				productWrap)
																				.attr(
																						"src",
																						ctx
																								+ '/'
																								+ result.content.productPicUrl);
																		$(
																				"dl:nth-child(3) .cp_intro a",
																				productWrap)
																				.attr(
																						"href",
																						result.content.productUrl);
																		$(
																				"dl:nth-child(3) .cp_intro a",
																				productWrap)
																				.html(
																						result.content.product);
																		$(
																				"dl:nth-child(3) .jspPane > div",
																				productWrap)
																				.html(
																						result.content.productProfile);
																		$(
																				"dl:nth-child(2) textarea",
																				productWrap)
																				.text(
																						result.content.productProfile);
																		$(
																				"dl:nth-child(3)",
																				productWrap)
																				.removeClass(
																						"dn");
																		$(
																				'.scroll-pane')
																				.jScrollPane();
																	} else {
																		if ($('.product_wrap').length == 1) {
																			$(
																					"dl:nth-child(1)",
																					productWrap)
																					.removeClass(
																							"dn");
																			$(
																					"dl:nth-child(2)",
																					productWrap)
																					.addClass(
																							"dn");
																			$(
																					"dl:nth-child(2) input[type!='submit'], dl:nth-child(2) textarea",
																					productWrap)
																					.val(
																							"");
																			$(
																					"dl:nth-child(2) textarea",
																					productWrap)
																					.text(
																							'');
																			$(
																					"dl:nth-child(3)",
																					productWrap)
																					.addClass(
																							"dn");
																		} else {
																			$(
																					".product_add")
																					.removeClass(
																							"dn");
																			$(
																					productWrap)
																					.remove();
																		}

																	}
																	$(form)
																			.find(
																					":submit")
																			.attr(
																					"disabled",
																					false);
																});
											}
										});
					});
	$('#Product')
			.on(
					"click",
					".product_edit",
					function() {
						// add nancy
						$('.newProduct .productForm span.error').hide();
						// end nancy
						var productWrap = $(this).parents(".product_wrap");
						var p_intro = $("dl:nth-child(2) textarea", productWrap)
								.text();
						if (p_intro) {
							p_intro = $.trim(p_intro.replace(/<br \/>/gi, ''));
						}
						/** nancy ע�͵�* */
						// $("dl:nth-child(2)
						// textarea",productWrap).val(p_intro);
						$("dl:nth-child(2) .word_count", productWrap).children(
								'span')
								.text(
										500 - $("dl:nth-child(2) textarea",
												productWrap).val().length);
						$("dl:nth-child(2)", productWrap).removeClass("dn");
						$("dl:nth-child(1)", productWrap).addClass("dn");
						$("dl:nth-child(3)", productWrap).addClass("dn");
					});
	$('#Product')
			.on(
					"click",
					".product_delete",
					function() {

						if (confirm('ȷ��Ҫɾ�������Ʒ��Ϣ��')) {
							var productId = $(this).next().val();
							var productWrap = $(this).parents(".product_wrap");
							if (productId == "") {
								if ($("#Product .product_wrap").length <= 1) {
									var val = $(
											"dl:nth-child(2) input[type!='submit']")
											.val();
									$("dl:nth-child(1)", productWrap)
											.removeClass("dn");
									$("dl:nth-child(2)", productWrap).addClass(
											"dn");
									$(
											"dl:nth-child(2) input[type!='submit'], dl:nth-child(2) textarea",
											productWrap).val("");
									$("dl:nth-child(3)", productWrap).addClass(
											"dn");
								} else {
									$(productWrap).remove();
								}
							} else {
								$
										.ajax(
												{
													type : 'POST',
													url : ctx
															+ '/cp/delProductInfo.json',
													data : {
														productId : productId
													},
													dataType : 'json'
												})
										.success(
												function(result) {
													if ($("#Product .product_wrap").length <= 1) {
														$("dl:nth-child(1)",
																productWrap)
																.removeClass(
																		"dn");
														$("dl:nth-child(2)",
																productWrap)
																.addClass("dn");
														$(
																"dl:nth-child(2) input[type!='submit'], dl:nth-child(2) textarea",
																productWrap)
																.val("");
														$(
																"dl:nth-child(2) textarea",
																productWrap)
																.text('');
														$(
																"dl:nth-child(2) .productShow img",
																productWrap)
																.attr("src", "");
														$(
																"dl:nth-child(2) .productShow",
																productWrap)
																.hide();
														$(
																"dl:nth-child(2) .productNo",
																productWrap)
																.show();
														$("dl:nth-child(3)",
																productWrap)
																.addClass("dn");
													} else {
														$(productWrap).remove();
													}

												});
							}
							$(".product_add").removeClass("dn");

							$("#Product .product_wrap").each(
									function(i) {
										$("input[type='file']", this).attr(
												"id", "myfiles" + i);
									});
						}
					});

	// countdown
	/*
	 * $('#Product
	 * .productForm').on('keyup','.s_textarea',function(){alert(111);
	 */
	/** edit nancy* */
	$('#Product').on(
			'keyup',
			' .productForm .s_textarea',
			function() {
				// textCounter('productProfile', '', 500);
				var field = $(this);
				var len = $.trim(field.val()).length;
				/*
				 * if ($.trim(field.val()).length > 500) {
				 * field.val($.trim(field.val()).substring(0, 500)); } else {
				 * field.next('.word_count').children('span').text(500 -
				 * $.trim(field.val()).length); }
				 */
				/** add nancy* */
				if (len > 500) {
					field.val(field.val().substring(0, 500));
				} else if ($(this).siblings('span').length > 0
						&& (len > 10 || len == 10)) {
					$(this).siblings('span').hide();
				} else if ($(this).siblings('span').length > 0 && len < 10) {
					$(this).siblings('span').show();
				} else {
					field.next('.word_count').children('span').text(500 - len);
				}
				/** end nancy* */
			});

	/***************************************************************************
	 * �༭��˾��Ʒ��֤
	 */
	$('.productForm')
			.each(
					function() {
						$(this)
								.validate(
										{
											onkeyup : false,
											// focusCleanup:true,
											rules : {
												myfiles : {
													required : false
												},
												product : {
													required : false,
													checkNum : true,
													specialchar : true,
													rangeLenStr : [ 1, 10 ]
												},
												productUrl : {
													/*
													 * required: false,
													 * checkUrlNot:true,
													 * maxlength:80
													 */
													required : false,
													checkUrlNot : true,
													maxlength : 120
												},
												productProfile : {
													/*
													 * required: false,
													 * minlength: 10,
													 * maxlength:500
													 */
													required : false,
													checkNum : true,
													specialchar : true,
													rangeLenStr : [ 10, 500 ]
												}
											},
											messages : {
												product : {
													checkNum : "��������Ч�Ĳ�Ʒ���",
													specialchar : "��������Ч�Ĳ�Ʒ���",
													rangeLenStr : "������1-10�ֵĲ�Ʒ���"
												},
												productUrl : {
													checkUrlNot : "��������Ч�Ĳ�Ʒ��ҳ���Ʒ���ص�ַ",
													maxlength : "������120�ַ����ڵ���ַ"
												},
												productProfile : {
													/*
													 * minlength:"������10-500�ֵĲ�Ʒ���",
													 * maxlength:"������10-500�ֵĲ�Ʒ���"
													 */
													checkNum : "��������Ч�Ĳ�Ʒ���",
													specialchar : "��������Ч�Ĳ�Ʒ���",
													rangeLenStr : "������10-500�ֵĲ�Ʒ���"
												}
											},
											submitHandler : function(form) {
												var companyId = $('#companyId')
														.val();
												;
												var productId = $(
														'.product_id', form)
														.val();
												var productPicUrl = $(
														'.productInfos', form)
														.val();
												var product = $(
														'input[name="product"]',
														form).val() != '�������Ʒ���' ? $(
														'input[name="product"]',
														form).val()
														: '';
												var productUrl = $
														.trim($(
																'input[name="productUrl"]',
																form).val()) != '�������Ʒ��ַ' ? $
														.trim($(
																'input[name="productUrl"]',
																form).val())
														: '';
												if (productUrl != ''
														&& productUrl
																.substring(0, 7) != 'http://') {
													productUrl = 'http://'
															+ productUrl;
												}
												var productProfile = $(
														'textarea[name="productProfile"]',
														form).val() != '��ֶ���ϸ������˾��顢��ҵ�Ļ���' ? $(
														'textarea[name="productProfile"]',
														form).val()
														: '';
												var resubmitToken = $(
														'#resubmitToken').val();
												var productWrap = $(form)
														.parents(
																".product_wrap");
												$(form).find(":submit").attr(
														"disabled", true);
												$
														.ajax(
																{
																	type : 'POST',
																	url : ctx
																			+ '/cp/saveCompanyProduct.json',
																	data : {
																		companyId : companyId,
																		id : productId,
																		type : 1,
																		productPicUrl : productPicUrl,
																		product : product,
																		productUrl : productUrl,
																		productProfile : productProfile,
																		resubmitToken : resubmitToken
																	},
																	dataType : 'json'
																})
														.success(
																function(result) {
																	if (null != result.resubmitToken
																			&& '' != result.resubmitToken) {
																		$(
																				'#resubmitToken')
																				.val(
																						result.resubmitToken);
																	}
																	if (result.success) {
																		$(
																				"dl:nth-child(1)",
																				productWrap)
																				.addClass(
																						"dn");

																		$(
																				"dl:nth-child(2)",
																				productWrap)
																				.addClass(
																						"dn");
																		$(
																				"dl:nth-child(2) .product_id",
																				productWrap)
																				.val(
																						result.content.id);

																		$(
																				"dl:nth-child(3) img",
																				productWrap)
																				.attr(
																						"src",
																						ctx
																								+ '/'
																								+ result.content.productPicUrl);
																		$(
																				"dl:nth-child(3) .cp_intro a",
																				productWrap)
																				.attr(
																						"href",
																						result.content.productUrl);
																		$(
																				"dl:nth-child(3) .cp_intro a",
																				productWrap)
																				.html(
																						result.content.product);
																		$(
																				"dl:nth-child(3) .jspPane > div",
																				productWrap)
																				.html(
																						result.content.productProfile);
																		$(
																				"dl:nth-child(2) textarea",
																				productWrap)
																				.text(
																						result.content.productProfile);
																		$(
																				"dl:nth-child(3)",
																				productWrap)
																				.removeClass(
																						"dn");

																		$(
																				'.scroll-pane')
																				.jScrollPane();
																	} else {
																		if ($('.product_wrap').length == 1) {
																			$(
																					"dl:nth-child(1)",
																					productWrap)
																					.removeClass(
																							"dn");
																			$(
																					"dl:nth-child(2)",
																					productWrap)
																					.addClass(
																							"dn");
																			$(
																					"dl:nth-child(2) input[type!='submit'], dl:nth-child(2) textarea",
																					productWrap)
																					.val(
																							"");
																			$(
																					"dl:nth-child(2) textarea",
																					productWrap)
																					.text(
																							'');
																			$(
																					"dl:nth-child(3)",
																					productWrap)
																					.addClass(
																							"dn");
																		} else {
																			$(
																					productWrap)
																					.remove();
																		}
																	}
																	$(form)
																			.find(
																					":submit")
																			.attr(
																					"disabled",
																					false);
																});
											}
										});

					});// end

	/***************************************************************************
	 * �༭��˾��Ϣ-���Ͻ�
	 */
	$('#editCompanyDetail').click(function() {
		$(this).hide();
		$('.c_detail').addClass('c_detail_bg');
		$('.c_box .oneword').hide();
		$('.editDetail').show();
	});

	/***************************************************************************
	 * ȡ��༭��˾��Ϣ
	 */
	$('#cancelDetail').click(function() {
		$('#editCompanyDetail').show();
		$('.c_box .oneword').show();
		$('.editDetail').hide();
		if ($('#addLabels').css('display') == 'none') {
			$('.c_detail').removeClass('c_detail_bg');
		}
	});
	/*********************************���� �༭��˾��Ϣ*******************************************/
	$('#companyFeatures').focus(function() {
		$('span.error').hide();
	})
	$("#editDetailForm")
			.validate(
					{
						onkeyup : false,
						// focusCleanup:true,
						rules : {
							companyShortName : {
								required : true,
								specialchar : true,
								maxlenStr : 40
							},
							companyFeatures : {
								required : true,
								/*
								 * minlength:5, maxlength:50
								 */
								checkNum : true,
								rangeLenStr : [ 5, 50 ]
							}
						},
						messages : {
							companyShortName : {
								required : "�����빫˾���",
								specialchar : "��������Ч�Ĺ�˾��ƣ��磺����",
								maxlenStr : "������40�����ڵĹ�˾���"
							},
							companyFeatures : {
								required : "������5-50�ֵ�һ�仰����",
								/*
								 * minlength:"������5-50�ֵ�һ�仰����",
								 * maxlength:"������5-50�ֵ�һ�仰����"
								 */
								checkNum : "��������Ч��һ�仰����",
								rangeLenStr : "������5-50�ֵ�һ�仰����"
							}
						},
						submitHandler : function(form) {
							var uidAndSession = "uid=" + $.cookie("jrqUid")
									+ "&sessionId=" + $.cookie("sessionId");
							var corpid = $.cookie("corpid");
							var companyName = $('#companyName').val() != $(
									'#companyName').attr("placeholder") ? $(
									'#companyName').val() : '';
							var companyShortName = $('#companyShortName').val() != $(
									'#companyShortName').attr("placeholder") ? $(
									'#companyShortName').val()
									: '';
							var companyFeatures = $('#companyFeatures').val() != $(
									'#companyFeatures').attr("placeholder") ? $(
									'#companyFeatures').val()
									: '';
							$(form).find(":submit").attr("disabled", true);
							$
									.ajax(
											{
												type : 'POST',
												url : 'saveCompanyInfo.action',
												data : {
													params : uidAndSession
															+ 'flag=editDetailForm'
															+ '&corpid='
															+ corpid
															+ '&company.corpname='
															+ companyName
															+ '&company.corpalias='
															+ companyShortName
															+ '&company.slogan='
															+ companyFeatures
												},
												dataType : 'json'
											})
									.success(
											function(result) {
												if (result.success) {
													if (result.content.companyShortName != '') {
														$('.c_box h2')
																.text(
																		result.content.companyShortName);
														$('.c_box h2')
																.attr(
																		"title",
																		result.content.companyShortName);
														/*
														 * $('.c_box
														 * h1.fullname').show()
														 */
														$('.c_box h1.fullname')
																.css('display',
																		'block');// bug69������֤
													} else {
														$('.c_box h2')
																.text(
																		$(
																				'.c_box h1.fullname')
																				.text());
														$('.c_box h2')
																.attr(
																		"title",
																		$(
																				'.c_box h1.fullname')
																				.attr(
																						"title"));
														$('.c_box h1.fullname')
																.hide();
													}
													$('.oneword span')
															.text(
																	result.content.companyFeatures);
													if ($('#addLabels').css(
															"display") == 'none') {
														$('.editDetail').hide();
														$('#editCompanyDetail')
																.show();
														$('.c_detail')
																.removeClass(
																		'c_detail_bg');
														$('.c_box .oneword')
																.show();
													} else {
														$('.editDetail').hide();
														$('#editCompanyDetail')
																.show();
														$('.c_box .oneword')
																.show();
													}
												} else {
													$('#beError').text(
															result.msg).show();
												}
												$(form).find(":submit").attr(
														"disabled", false);
											});
						}
					});

	/***************************************************************************
	 * ��ӹ�˾����
	 */
	$('.newIntro #companyProfile').bind(
			'keyup',
			function() {
				if (1000 - $('.newIntro .word_count ').find('span').html() > 20
						|| 1000 - $('.newIntro .word_count ').find('span')
								.html() == 20) {
					$('.newIntro span.error').hide();
				}
				;
			})
	$('#Profile')
			.on(
					'click',
					'#editIntro,#addIntro',
					function() {
						// add nancy
						$('.newIntro #companyDesForm span.error').hide();
						// end nancy
						var profileWrap = $(this).parents('.profile_wrap');
						var c_intro = $("dl:nth-child(3) .c_intro", profileWrap)
								.html();
						if (c_intro) {
							c_intro = $.trim(c_intro.replace(/<br>/gi, '\r\n'));
						}
						$("dl:nth-child(2) textarea", profileWrap).val(c_intro);
						$("dl:nth-child(2) .word_count", profileWrap).children(
								'span').text(
								1000 - $.trim($("dl:nth-child(2) textarea",
										profileWrap).val()).length);
						$("dl:nth-child(1)", profileWrap).hide();
						$("dl:nth-child(2)", profileWrap).show();
						$("dl:nth-child(3)", profileWrap).hide();

					});

	/*
	 * $('.newIntro #companyProfile').focus(function(){ //alert($(this).length);
	 * console.log($(this).has('span.error').length); if($(this).length>20){
	 * alert(11); } if($(this).has('span.error')){
	 * $(this).find('span.error').hide(); } })
	 */

	$('#companyDesForm')
			.submit(
					function() {
						if ($('textarea', this).val() == $('textarea', this)
								.attr('placeholder')) {
							$('textarea', this).val("");
						}
					})
			.validate(
					{
						onkeyup : false,
						// focusCleanup:true ,
						onfocusout : false,
						onsubmit : true,
						rules : {
							companyProfile : {
								required : false,
								/* rangeLen: [20,1000] */
								rangeLenStr : [ 10, 1000 ]
							}
						},
						messages : {
							companyProfile : {
								/* rangeLen:"������20-1000�ֵĹ�˾����" */
								rangeLenStr : "������10-1000�ֵĹ�˾����"
							}
						},
						submitHandler : function(form) {
							var uidAndSession = "uid=" + $.cookie("jrqUid")
									+ "&sessionId=" + $.cookie("sessionId");
							var corpid = $.cookie("corpid");
							var companyProfile = $.trim($('#companyProfile')
									.val()) != $('#companyProfile').attr(
									'placeholder') ? $
									.trim($('#companyProfile').val()) : '';
							var profileWrap = $(form).parents(".profile_wrap");
							companyProfile = companyProfile.replace(/\r\n/g,
									'<br />');
							companyProfile = companyProfile.replace(/\n/g,
									'<br />');
							$(form).find(":submit").attr("disabled", true);
							$
									.ajax(
											{
												type : 'POST',
												url : 'saveCompanyInfo.action',
												data : {
													params : uidAndSession
															+ 'flag=companyDesForm'
															+ '&corpid='
															+ corpid
															+ '&company.intro='
															+ companyProfile
												},
												dataType : 'json'
											})
									.success(
											function(result) {
												if (result.success) {
													if (result.content == '') {
														$("dl:nth-child(1)",
																profileWrap)
																.show();
														$(
																"dl:nth-child(2) textarea",
																profileWrap)
																.val("");
														$("dl:nth-child(2)",
																profileWrap)
																.hide();
														$(
																"dl:nth-child(3) .c_intro",
																profileWrap)
																.html("");
														$("dl:nth-child(3)",
																profileWrap)
																.hide();
													} else {
														$("dl:nth-child(1)",
																profileWrap)
																.hide();
														var remark = result.content;
														if (remark) {
															remark = $
																	.trim(remark
																			.replace(
																					/<br \/>/gi,
																					''));
														}
														$(
																"dl:nth-child(2) textarea",
																profileWrap)
																.val(remark);
														$("dl:nth-child(2)",
																profileWrap)
																.hide();
														$(
																"dl:nth-child(3) .c_intro",
																profileWrap)
																.html(
																		result.content);
														$("dl:nth-child(3)",
																profileWrap)
																.show();
													}
												} else {
													alert("����ʧ��");
												}
												$(form).find(":submit").attr(
														"disabled", false);
											});
						}
					});

	// countdown
	$('#companyProfile')
			.bind(
					'keyup',
					function() {
						// textCounter('companyProfile', '', 1000);
						/** add nancy* */
						var field = $(this);
						var len = $.trim(field.val()).length;
						if ($.trim(field.val()).length > 1000) {
							field.val(field.val().substring(0, 1000));
						} else if ($(this).siblings('span').length > 0
								&& (len > 20 || len == 20)) {
							$(this).siblings('span').hide();
						} else if ($(this).siblings('span').length > 0
								&& len < 20) {
							$(this).siblings('span').show();
						} else {
							field.next('.word_count').children('span').text(
									1000 - len);
						}
						/** end nancy* */
					});

	/***************************************************************************
	 * ȡ��˾����
	 */
	/*
	 * $('#companyProfile').blur(function(){ $(this).validate({ ignore: "ignore"
	 * }); })
	 */
	$('#companyDesForm').click(function(e) {
		e.stopPropagation();
	})
	$('#delProfile').bind(
			'click',
			function(e) {

				var profileWrap = $(this).parents(".profile_wrap");
				if ($('.c_intro', profileWrap).html() == '') {
					$("dl:nth-child(1)", profileWrap).show();
					$("dl:nth-child(2)", profileWrap).hide();
					$("dl:nth-child(3)", profileWrap).hide();
				} else {
					$("dl:nth-child(1)", profileWrap).hide();
					var oldVal = $("dl:nth-child(3)", profileWrap).find(
							'.c_intro').text();
					$("dl:nth-child(2)", profileWrap).find('#companyProfile')
							.val(oldVal);
					$("dl:nth-child(2)", profileWrap).hide();
					$("dl:nth-child(3)", profileWrap).show();
				}
				/*
				 * if($('#companyProfile').val() == '' || $('.c_intro' ,
				 * profileWrap).html() == ''){
				 * $("dl:nth-child(1)",profileWrap).show();
				 * $("dl:nth-child(2)",profileWrap).hide();
				 * $("dl:nth-child(3)",profileWrap).hide(); }else
				 * if($('.c_intro' , profileWrap).html() != ''){
				 * $("dl:nth-child(1)",profileWrap).hide(); var oldVal =
				 * $("dl:nth-child(3)",profileWrap).find('.c_intro').text();
				 * $("dl:nth-child(2)",profileWrap).find('#companyProfile').val(oldVal);
				 * $("dl:nth-child(2)",profileWrap).hide();
				 * $("dl:nth-child(3)",profileWrap).show(); }
				 */

			});
	/***************************************************************************
	 * ɾ��˾����
	 */
	/*
	 * $('#delProfile').bind('click',function(){ var companyId =
	 * $('#companyId').val(); var companyProfile = ''; var profileWrap =
	 * $(this).parents(".profile_wrap"); $.ajax({ type:'POST',
	 * url:ctx+'/c/saveCompanyProfile.json', data:{ companyId:companyId,
	 * companyProfile:companyProfile }, dataType:'json'
	 * }).success(function(result) { if(result.success){
	 * $("dl:nth-child(1)",profileWrap).show(); $("dl:nth-child(2)
	 * textarea",profileWrap).val(""); $("dl:nth-child(2)",profileWrap).hide();
	 * $("dl:nth-child(3) .c_intro",profileWrap).val("");
	 * $("dl:nth-child(3)",profileWrap).hide(); }else{ alert(result.msg); } });
	 * });
	 */

	/***************************************************************************
	 * �༭��˾��Ϣ(�Ҳ�)
	 */
	$('#editTags').click(function() {
		$('#c_tags_show').hide();
		$('#c_tags_edit').show();
	});
	$('#tagForms')
			.validate(
					{
						/*
						 * onkeyup: false, focusCleanup:true,
						 */
						rules : {
							city : {
								required : true,
								checkCity : true,
								maxlenStr : 10
							},
							industryField : {
								required : true
							},
							companySize : {
								required : true
							},
							companyUrl : {
								required : true,
								checkUrl : true,
								maxlength : 120
							}
						},
						messages : {
							city : {
								required : "�����빫˾���ڳ��У��磺����",
								/* maxlength:"������20�ַ����ڵĹ�˾��ַ" */
								maxlenStr : "��������Ч�Ĺ�˾���ڳ��У��磺����"
							},
							industryField : {
								required : "��ѡ��˾��ҵ����"
							},
							companySize : {
								required : "��ѡ��˾��ģ"
							},
							companyUrl : {
								required : "�����빫˾��ַ���磺www.ycrjhr.com",
								checkUrl : "��������Ч�Ĺ�˾��ַ",
								maxlength : "������120�ַ����ڵ���ַ"
							}
						},
						errorPlacement : function(label, element) {
							if (element.attr("type") == "hidden") {
								label.insertAfter($(element).parent());
							} else {
								label.insertAfter(element);
							}
						},
						submitHandler : function(form) {
							var uidAndSession = "uid=" + $.cookie("jrqUid")
									+ "&sessionId=" + $.cookie("sessionId");
							var corpid = $.cookie("corpid");
							var city = $('#city', form).val();
							var industryField = $('#industryField', form).val();
							var companySize = $('#companySize', form).val();
							var companyUrl = $('#companyUrl', form).val();
							/*
							 * if(companyUrl.substring(0,7) != 'http://'){
							 * companyUrl = 'http://' + companyUrl; }
							 */
							$(form).find(":submit").attr("disabled", true);
							$
									.ajax(
											{
												type : 'POST',
												url : 'saveCompanyInfo.action',
												data : {
													params : uidAndSession
															+ 'flag=tagForms'
															+ '&corpid='
															+ corpid
															+ '&company.city='
															+ city
															+ '&company.corpindustry='
															+ industryField
															+ '&company.corpscale='
															+ companySize
															+ '&company.website='
															+ companyUrl
												},
												dataType : 'json'
											})
									.success(
											function(result) {
												if (result.success) {
													$('#city', form).val(city);
													$('#industryField', form)
															.val(industryField);
													$('#companySize', form)
															.val(companySize);
													$('#companyUrl', form).val(
															companyUrl);
													$('#comCity', form).val(
															city);
													$('#comInd', form).val(
															industryField);
													$('#comSize', form).val(
															companySize);
													$('#comUrl', form).val(
															companyUrl);
													if (companyUrl
															.indexOf('http://') != -1
															|| companyUrl
																	.indexOf('https://') != -1) {
														$('#c_tags_show table')
																.html(
																		'<tr><td>�ص�</td><td>'
																				+ result.content.city
																				+ '</td></tr>'
																				+ '<tr><td>����</td><td>'
																				+ result.content.industryField
																				+ '</td></tr>'
																				+ '<tr><td>��ģ</td><td>'
																				+ result.content.companySize
																				+ '</td></tr>'
																				+ '<tr><td>��ҳ</td><td><a href="'
																				+ result.content.companyUrl
																				+ '" target="_blank">'
																				+ result.content.companyUrl
																				+ '</a></td></tr>');
													} else {
														$('#c_tags_show table')
																.html(
																		'<tr><td>�ص�</td><td>'
																				+ result.content.city
																				+ '</td></tr>'
																				+ '<tr><td>����</td><td>'
																				+ result.content.industryField
																				+ '</td></tr>'
																				+ '<tr><td>��ģ</td><td>'
																				+ result.content.companySize
																				+ '</td></tr>'
																				+ '<tr><td>��ҳ</td><td><a href="http://'
																				+ result.content.companyUrl
																				+ '" target="_blank">'
																				+ result.content.companyUrl
																				+ '</a></td></tr>');
													}
													$('#c_tags_show').show();
													$('#c_tags_edit').hide();
												} else {
													if (result.msg == ''
															|| result.msg == null
															|| result.msg == undefined) {
														alert("����ʧ��");
													} else {
														alert(result.msg);
													}

												}
												$(form).find(":submit").attr(
														"disabled", false);
											});
						}
					});

	/***************************************************************************
	 * select��
	 */
	$(document).click(function() {
		/*
		 * var industry = []; if($('#box_ind li.current').length > 2){
		 * alert('��ҵ��������ѡ2��'); }else{ $('#box_ind li.current').each(function(){
		 * industry.push($(this).text()); }); if(industry.join() == ''){
		 * $('#select_ind').val('��ѡ����ҵ����'); }else{
		 * $('#select_ind').val(industry.join()); }
		 * $('#industryField').val(industry.join()); $('#box_ind').hide(); }
		 */
		$('#box_sca').hide();
		$('#box_fin').hide();
		$('#typeForm .selectBoxShort').hide();
		$('#select_ind').removeClass('select_tags_focus');
		$('#select_fin').removeClass('select_tags_focus');
		$('#select_sca').removeClass('select_tags_focus');
	});

	/***************************************************************************
	 * ѡ��ҵ(��ѡ)
	 */

	$('#select_ind').bind('click', function(e) {
		e.stopPropagation();
		$(this).addClass('select_tags_focus');
		$('#select_fin').removeClass('select_tags_focus');
		$('#select_sca').removeClass('select_tags_focus');
		$('#box_ind').show();
		$('#box_sca').hide();
		$('#box_fin').hide();
	});
	$('#box_ind').on(
			'click',
			'ul li',
			function(e) {
				e.stopPropagation();
				var industry = [];
				if ($(this).hasClass('current')) {
					$(this).removeClass('current');
					$('#box_ind li.current').each(function() {
						industry.push($(this).text());
					});
					$('#select_ind').val(industry.join());
					$('#industryField').val(industry.join());
				} else {
					if ($(this).siblings('li.current').length == 0) {
						$(this).addClass('current');
						industry.push($(this).text());
						$('#select_ind').val(industry.join());
						$('#industryField').val(industry.join());
					} else if ($(this).siblings('li.current').length == 1) {
						$(this).addClass('current');
						$('#box_ind li.current').each(function() {
							industry.push($(this).text());
						});
						$('#select_ind').val(industry.join()).removeClass(
								'select_tags_focus');
						$('#industryField').val(industry.join());
						$('#box_ind').hide();
					} else if ($(this).siblings('li.current').length >= 2) {
						alert('��ҵ��������ѡ2��');
					}
				}
			});

	/***************************************************************************
	 * ѡ��ģ
	 */
	$('#select_sca').bind('click', function(e) {
		e.stopPropagation();
		$(this).addClass('select_tags_focus');
		$('#select_ind').removeClass('select_tags_focus');
		$('#box_sca').show();
		$('#box_fin').hide();
		$('#typeForm .selectBoxShort').hide();
		$('#box_ind').hide();
	});
	$('#box_sca').on('click', 'ul li', function(e) {
		e.stopPropagation();
		var sca = $(this).text();
		$('#select_sca').val(sca).removeClass('select_tags_focus');
		$('#companySize').val(sca);
		$('#box_sca').hide();
	});

	$('#box_fin,#box_sca').bind('click', function(e) {
		e.stopPropagation();
	});

	/***************************************************************************
	 * ȡ���޸��Ҳ�features
	 */
	$('#cancelFeatures').click(function() {
		var form = $(this).parents('#tagForms');
		var comCity = $('#comCity', form).val();
		var comInd = $('#comInd', form).val();
		var comFin = $('#comFin', form).val();
		var comSize = $('#comSize', form).val();
		var comUrl = $('#comUrl', form).val();
		$('#city', form).val(comCity);
		$('#select_ind', form).val(comInd);
		$('#industryField', form).val(comInd);
		$('#companySize', form).val(comSize);
		$('#select_sca', form).val(comSize);
		$('#companyUrl', form).val(comUrl);
		$('#c_tags_edit').hide();
		$('#c_tags_show').show();
	});

	/***************************************************************************
	 * ѡ����ҵ����
	 */
	var cancelButton = null;
	$(".c_stages").on("click", "#select_fin", function(e) {
		e.stopPropagation();
		/*
		 * $(this).addClass('select_tags_focus');
		 * $('#select_ind').removeClass('select_tags_focus');
		 * $('#select_sca').removeClass('select_tags_focus');
		 */
		$('#box_fin').show();
		/* $('#stagesList .selectBoxShort').hide(); */
		$('#box_sca').hide();
		$('#box_ind').hide();
	})
	$('.c_stages #typeForm #box_fin').on('click', 'li', function(event) {
		event.stopPropagation();
		var _this = $(this);
		loop(_this);
	});
	function loop(ele) {
		var fin = ele.text();
		var ul = ele.parents("div.stageSelect").next("ul#stagesList");
		$('#select_fin').val(fin);// .removeClass('select_tags_focus');
		$('#companyType').val(fin);
		var val = $("#select_fin").val();
		$('#box_fin').hide();
		if (val == "δ����" || val == "���й�˾" || val == "����Ҫ����") {
			ul.hide();
		} else {
			ul.show();
			var index = ele.index() + 1;
			ul.find("li").remove();
			ele.prevAll().addBack().slice(1, index).each(
					function(i) {
						var str = $('#cloneInvest').html();
						ul.append('<li>' + str + '</li>');
						ul.find("li").eq(index - 1).remove();
						var txt = $(this).text()
						ul.find("li").eq(i).find("input[type='button']").val(
								txt);
						ul.find("li").eq(i).find("input[type='hidden']").val(
								txt);
						ul.find("li").eq(i).find("input[type='text']").attr(
								"name", 'stageorg' + i);
					})
		}
	}

	/***************************************************************************
	 * ѡ��˾����
	 */
	var typeForm = null;
	$('.c_stages .c_edit').bind(
			'click',
			function() {
				submitStage()
				$(this).hide();
				$('.c_stages .stageshow').hide();
				typeForm = $('.c_stages #typeForm').clone();
				$('#typeForm #stagesList').find("li").each(function(i) {
					if ($(this).find("input[type='hidden']").val() == "") {
						$(this).remove();
					}
				})
				if (cancelButton != null) {
					$("#cancelStages").remove();
					$("#typeForm").find("input[type='submit']").after(
							cancelButton);
				}
				$('.c_stages #typeForm').show();
				$('#box_sca').hide();
				$("#stagesList>li").each(
						function(i) {
							$(this).find("input[type='text']").attr("name",
									'stageorg' + i);
						})
				if ($(".stageshow li").eq(1).text() == "") {
					var num = $('#select_fin').val();
					var li = $('#box_fin ul').find("li");
					var ul = $("ul#stagesList");
					$.each(li, function(index, item) {
						if (num == "���̶���" || num == "�������/����" || num == "������ҵ"
								|| num == "�����?" || num == "�������/��ӯ���"
								|| num == "��ҵ��λ" || num == "����") {
							ul.hide();
						} else if (num == $(this).text()) {
							ul.show();
							var index = index + 1;
							ul.find("li").remove();
							$(this).prevAll().addBack().slice(1, index).each(
									function(i) {
										var str = $('#cloneInvest').html();
										ul.append('<li>' + str + '</li>');
										ul.find("li").eq(index - 1).remove();
										var txt = $(this).text()
										ul.find("li").eq(i).find(
												"input[type='button']")
												.val(txt);
										ul.find("li").eq(i).find(
												"input[type='hidden']")
												.val(txt);
										ul.find("li").eq(i).find(
												"input[type='text']").attr(
												"name", 'stageorg' + i);
									})
						}
					})
				}
			});

	$('.c_stages').on('click', '.select_invest', function(e) {
		e.stopPropagation();
		$('#box_sca').hide();
		/*
		 * $(this).parents('li').siblings().children('.selectBoxShort').hide();
		 * $(this).siblings('.selectBoxShort').show();
		 */
	});
	/*
	 * $('.c_stages').on('click','.selectBoxShort li',function(e){
	 * e.stopPropagation(); var invest = $(this).html(); var _li =
	 * $(this).parents('li');
	 * $('.select_invest,.select_invest_hidden',_li).val(invest);
	 * $(this).parents('.selectBoxShort').hide(); });
	 */
	/*
	 * $('.c_stages').on('change','.select_invest',function(){ var str =
	 * $('#cloneInvest').html(); $('#stagesList').append('<li>'+str+'</li>');
	 * });
	 */

	// ��˾���� submit
	function submitStage() {
		$('.c_stages #typeForm')
				.validate(
						{
							onkeyup : false,
							/* focusCleanup:true */
							rules : {
								stageorg0 : {
									required : false,
									/* maxlength:200 */
									maxlenStr : 50
								},
								stageorg1 : {
									required : false,
									maxlenStr : 50
								},
								stageorg2 : {
									required : false,
									maxlenStr : 50
								},
								stageorg3 : {
									required : false,
									maxlenStr : 50
								},
								stageorg4 : {
									required : false,
									maxlenStr : 50
								}
							},
							messages : {
								stageorg0 : {
									/* maxlength:"������200�����ڵ�Ͷ�ʻ�" */
									maxlenStr : "��ѡ��˾����"
								},
								stageorg1 : {
									maxlenStr : "��ѡ��˾����"
								},
								stageorg2 : {
									maxlenStr : "��ѡ��˾����"
								},
								stageorg3 : {
									maxlenStr : "��ѡ��˾����"
								},
								stageorg4 : {
									maxlenStr : "��ѡ��˾����"
								}
							},
							errorPlacement : function(error, element) {
								error.appendTo(element.parent());
							},
							submitHandler : function(form) {
								/*
								 * $('.c_stages').on('click','.btn_small',function(){
								 * var form = $(this).parents('#typeForm');
								 */
								/*$(form).find(":submit").attr("disabled", true);
								var uidAndSession = "uid=" + $.cookie("jrqUid")
										+ "&sessionId=" + $.cookie("sessionId");
								//var corpid = $.cookie("corpid");
								var financeStage = $('#financeStage').val();
								var stages = '';
								var stage1, org1;
								stages += '[';
								$('#stagesList > li')
										.each(
												function(i) {
													stage1 = $(this)
															.children(
																	'input[name="select_invest_hidden"]')
															.val();
													org2 = $(this)
															.children(
																	'input[type="text"]')
															.val() != $(this)
															.children(
																	'input[type="text"]')
															.attr('placeholder') ? $(
															this)
															.children(
																	'input[type="text"]')
															.val()
															: "";
													var org1 = $.trim(org2);
													if (i == $('#stagesList > li').length - 1) {
														stages += '{"stage":"'
																+ stage1
																+ '","org":"'
																+ org1 + '"}';
													} else {
														stages += '{"stage":"'
																+ stage1
																+ '","org":"'
																+ org1 + '"},';
													}
												});
								if ($("#companyType").val() == "���̶���"
										|| $("#companyType").val() == "�������/����"
										|| $("#companyType").val() == "������ҵ"
										|| $("#companyType").val() == "�����?"
										|| $("#companyType").val() == "�������/��ӯ���"
										|| $("#companyType").val() == "��ҵ��λ"
										|| $("#companyType").val() == "����") {
									stages = "";
								}
								stages += ']';
								var resubmitToken = $('#resubmitToken').val();
								$
										.ajax(
												{
													type : 'POST',
													url : 'saveCompanyInfo.action',
													data : {
														resubmitToken : resubmitToken,
														params : uidAndSession
																+ 'flag=typeForm'
																+ '&corpid='
																+ corpid
																+ '&company.corpquality='
																+ companyType
													},
													dataType : 'json'
												})
										.done(
												function(result) {
													if (null != result.resubmitToken
															&& '' != result.resubmitToken) {
														$('#resubmitToken')
																.val(
																		result.resubmitToken);
													}
													if (result.success) {
														$(
																'.c_stages .stageshow li')
																.eq(0)
																.children(
																		'span')
																.html(
																		result.msg);
														if (result.msg == "δ����"
																|| result.msg == "���й�˾"
																|| result.msg == "����Ҫ����") {
															$(
																	'.c_stages .stageshow>li')
																	.eq(1)
																	.remove();
														} else {
															if (result.content != '') {
																if ($('.c_stages .stageshow li').length == 1) {
																	$(
																			'.c_stages .stageshow')
																			.append(
																					'<li>Ͷ�ʻ�<span>'
																							+ result.content
																							+ '</span></li>');
																} else {
																	$(
																			'.c_stages .stageshow li')
																			.eq(
																					1)
																			.children(
																					'span')
																			.html(
																					result.content);
																}
															} else {
																$(
																		'.c_stages .stageshow')
																		.html(
																				'<li>Ŀǰ�׶Σ�<span class="c5">'
																						+ result.msg
																						+ '</span></li>');
															}
														}
														cancelButton = null;
														$(form).hide();
														$(
																'.c_stages .stageshow')
																.show();
														$('.c_stages .c_edit')
																.show();
													} else {
														alert("����ʧ��");
													}
													$(form).find(":submit")
															.attr("disabled",
																	false);
												});*/
							}
						});
	}

	/***************************************************************************
	 * ȡ���޸��Ҳ෢չ�׶κ�Ͷ�ʻ�
	 */
	$('#cancelStages').on('click', function() {
		var stageWrapper = $(this).parents('.c_stages');
		cancelButton = $(this).clone(true);
		stageWrapper.children('dd').find('form').remove();
		stageWrapper.children('dd').append(typeForm);
		$('.c_stages .stageshow').show();
		$('.c_stages .c_edit').show();
		$('#typeForm #box_fin').on('click', 'li', function(event) {
			event.stopPropagation();
			var _this = $(this);
			loop(_this);
		});
		submitStage();
	});

	/***************************************************************************
	 * �ϴ�ͷ�񱳾���ɫ
	 */
	$('.new_portrait').on('mouseenter', 'input', function() {
		$('.portrait_upload').css('backgroundColor', '#7e9597');
	});
	$('.new_portrait').on('mouseleave', 'input', function() {
		$('.portrait_upload').css('backgroundColor', '#93b7bb');
	});

	/***************************************************************************
	 * textarea�ı����������
	 */
	/*
	 * $('textarea[name="companyProfile"]').keyup(function(){
	 * textCounter(companyProfile, word_count, 1000); });
	 * $('textarea[name="remark"]').keyup(function(){ textCounter(remark,
	 * word_count, 500); });
	 * $('textarea[name="productProfile"]').keyup(function(){
	 * textCounter(productProfile, word_count, 500); });
	 */

	/***************************************************************************
	 * ��˾��ȱ���
	 **************************************************************************/
	// add nancy
	$('#Reported').on('click', ' .reportForm input', function() {
		$(this).next('span.error').hide();
	});
	var Report = {
		obj : $('#Reported'),
		addReport : function() {
			var newReport = this.obj.find('.newReport').children('li').clone();
			this.obj.find('ul.reset').append(newReport).removeClass('dn');

			$('.reportForm', newReport)
					.validate(
							{
								onkeyup : false,
								focusCleanup : true,
								focusInvalid : false,
								rules : {
									articleTitle : {
										required : true,
										specialchar : true,
										checkNum : true,
										maxlenStr : 50
									},
									articleUrl : {
										required : true,
										checkUrl : true,
										maxlength : 500
									}
								},
								messages : {
									articleTitle : {
										required : "���������±���",
										specialchar : "��������Ч�����±���",
										checkNum : "��������Ч�����±���",
										maxlenStr : "������50�����ڵ����±���"
									},
									articleUrl : {
										required : "��������������",
										checkUrl : "��������Ч����������",
										maxlength : "������500�ַ����ڵ���������"
									}
								},
								submitHandler : function(form) {
									var articleTitle = $(
											'input[name="articleTitle"]', form)
											.val() != $(
											'input[name="articleTitle"]', form)
											.attr('placeholder') ? $(
											'input[name="articleTitle"]', form)
											.val() : '';
									var articleUrl = $(
											'input[name="articleUrl"]', form)
											.val() != $(
											'input[name="articleUrl"]', form)
											.attr('placeholder') ? $(
											'input[name="articleUrl"]', form)
											.val() : '';
									var articleId = $('.article_id', form)
											.val();
									var companyId = $('#companyId').val();
									var resubmitToken = $('#resubmitToken')
											.val();
									$(form).find(":submit").attr("disabled",
											true);
									$
											.ajax(
													{
														url : ctx
																+ '/article/save.json',
														type : 'POST',
														data : {
															title : articleTitle,
															url : articleUrl,
															id : articleId,
															companyId : companyId,
															resubmitToken : resubmitToken
														},
														dataType : 'json'
													})
											.done(
													function(result) {
														if (null != result.resubmitToken
																&& '' != result.resubmitToken) {
															$('#resubmitToken')
																	.val(
																			result.resubmitToken);
														}
														if (result.success) {
															var content = result.content;
															var title = '';
															var url = '';
															if (content.url
																	.substring(
																			0,
																			7) != 'http://') {
																url = 'http://'
																		+ content.url;
															} else {
																url = content.url;
															}

															title = content.title;

															$(form)
																	.siblings(
																			'a.article')
																	.html(title)
																	.attr(
																			{
																				href : url,
																				title : content.title
																			});
															$('.article_id',
																	form).val(
																	content.id);
															$(form)
																	.addClass(
																			'dn')
																	.siblings(
																			'a')
																	.show();
															$(form)
																	.children(
																			'.btn_cancel_s')
																	.addClass(
																			'report_delete')
																	.removeClass(
																			'report_cancel')
																	.text('ɾ��');
														} else {
															alert(result.msg);
														}
														$(form)
																.find(":submit")
																.attr(
																		"disabled",
																		false);
													});
								}
							});
		},
		editReport : function(o) {
			var report = o.siblings('a.article').attr('title');
			var url = o.siblings('a.article').attr('href');
			o.siblings('form').children('input').eq(0).val(report);
			o.siblings('form').children('input').eq(1).val(url);
			o.hide().siblings('a').hide().siblings('form').removeClass('dn');
		},
		delReport : function(o) {
			var reportObj = this.obj;
			var articleId = o.siblings('.article_id').val();
			$
					.ajax({
						url : ctx + '/article/del.json',
						type : 'POST',
						data : {
							id : articleId
						}
					})
					.done(
							function(result) {
								if (result.success) {
									o.parent('form').parent('li').remove();
									if (reportObj.find('ul.reset').children(
											'li').length == 0) {
										reportObj.find('.c_add').addClass('dn');
										reportObj.find('ul.reset').addClass(
												'dn')
												.siblings('.reported_info')
												.removeClass('dn');
									} else {
										reportObj.find('.c_add').removeClass(
												'dn');
									}
								} else {
									console.log(result.msg);
								}
							});
		}
	};
	$('#Reported .c_reported .c_add').bind('click', function() {
		if (Report.obj.find('ul.reset').children('li').length < 4) {
			Report.addReport();
		} else if (Report.obj.find('ul.reset').children('li').length = 4) {
			Report.addReport();
			$(this).addClass('dn');
		} else {
			$(this).addClass('dn');
		}
	});
	$('#Reported .c_reported .report_edit').bind('click', function() {
		$(this).parent('.reported_info').addClass('dn');
		$('#Reported .c_reported .c_add').removeClass('dn');
		Report.addReport();
	});
	$('#Reported').on('click', 'ul .c_edit', function() {
		Report.editReport($(this));
	});
	$('#Reported').on('click', 'ul .report_delete', function() {
		if (confirm('ȷ��Ҫɾ�����������')) {
			Report.delReport($(this));
		}
	});
	$('#Reported').on(
			'click',
			'ul .report_cancel',
			function() {
				$(this).parent('form').parent('li').remove();
				if (Report.obj.find('ul.reset').children('li').length == 0) {
					Report.obj.find('.c_add').addClass('dn');
					Report.obj.find('ul.reset').addClass('dn').siblings(
							'.reported_info').removeClass('dn');
				} else {
					Report.obj.find('.c_add').removeClass('dn');
				}
			});

	$('.reportForm')
			.each(
					function() {
						$(this)
								.validate(
										{
											onkeyup : false,
											focusCleanup : true,
											/*
											 * rules: { articleTitle: {
											 * required: true, specialchar:true,
											 * checkNum:true }, articleUrl: {
											 * required: true, checkUrl:true } },
											 * messages: { articleTitle: {
											 * required: "���������±���",
											 * specialchar:"��������Ч�����±���",
											 * checkNum:"��������Ч�����±���" },
											 * articleUrl: { required:
											 * "��������������", checkUrl:"��������Ч����������" } }
											 */
											rules : {
												articleTitle : {
													required : true,
													specialchar : true,
													checkNum : true,
													maxlenStr : 50
												},
												articleUrl : {
													required : true,
													checkUrl : true,
													maxlength : 500
												}
											},
											messages : {
												articleTitle : {
													required : "���������±���",
													specialchar : "��������Ч�����±���",
													checkNum : "��������Ч�����±���",
													maxlenStr : "������50�����ڵ����±���"
												},
												articleUrl : {
													required : "��������������",
													checkUrl : "��������Ч����������",
													maxlength : "������500�ַ����ڵ���������"
												}
											},
											submitHandler : function(form) {
												var articleTitle = $(
														'input[name="articleTitle"]',
														form).val() != $(
														'input[name="articleTitle"]',
														form).attr(
														'placeholder') ? $(
														'input[name="articleTitle"]',
														form).val()
														: '';
												var articleUrl = $(
														'input[name="articleUrl"]',
														form).val() != $(
														'input[name="articleUrl"]',
														form).attr(
														'placeholder') ? $(
														'input[name="articleUrl"]',
														form).val()
														: '';
												var articleId = $(
														'.article_id', form)
														.val();
												var companyId = $('#companyId')
														.val();
												var resubmitToken = $(
														'#resubmitToken').val();
												$(form).find(":submit").attr(
														"disabled", true);
												$
														.ajax(
																{
																	url : ctx
																			+ '/article/save.json',
																	type : 'POST',
																	data : {
																		title : articleTitle,
																		url : articleUrl,
																		id : articleId,
																		companyId : companyId,
																		resubmitToken : resubmitToken
																	},
																	dataType : 'json'
																})
														.done(
																function(result) {
																	if (null != result.resubmitToken
																			&& '' != result.resubmitToken) {
																		$(
																				'#resubmitToken')
																				.val(
																						result.resubmitToken);
																	}
																	if (result.success) {
																		var content = result.content;
																		var title = '';
																		var url = '';
																		if (content.url
																				.indexOf('http://') != -1
																				|| content.url
																						.indexOf('https://') != -1) {
																			url = content.url;
																		} else {
																			url = 'http://'
																					+ content.url;
																		}
																		title = content.title;

																		$(form)
																				.siblings(
																						'a.article')
																				.html(
																						title)
																				.attr(
																						{
																							href : url,
																							title : content.title
																						});
																		$(
																				'.article_id',
																				form)
																				.val(
																						content.id);
																		$(form)
																				.addClass(
																						'dn')
																				.siblings(
																						'a')
																				.show();
																	} else {
																		console
																				.log(result.msg);
																	}
																	$(form)
																			.find(
																					":submit")
																			.attr(
																					"disabled",
																					false);
																});
											}
										});
					});

});

/*******************************************************************************
 * �ϴ���˾logo
 */
var fileFlag;
$("#logo").change(function(){
	var objUrl = getObjectURL(this.files[0]) ;
	var companyPic = $("#logo").val();
	if(this.files[0].size/1024>1024){
		alert("ͼƬ������1M��");
		return;
	}
	var extStart=companyPic.lastIndexOf(".");
    var ext=companyPic.substring(extStart,companyPic.length).toUpperCase();
    if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
    	alert("ͼƬ����bmp,png,gif,jpeg,jpg��ʽ");
    	return;
    }
	if(objUrl!=null) {
		$("#logoShow img").attr("src", objUrl);
		if(companyPicFlag==1){
			deleteFile(companyPicName,2);
            $.ajax({  
        	       type : 'post',  
        	       url : 'saveCompanyInfo.action',  
        	       dataType : 'json',  
				   data : {
						params : uidAndSession
								+ '&flag=uploadCompanyPic'
								+ '&corpid='
								+ corpid
								+ '&company.logo=0'
					},
        	  	   success : function (result) {
        	  	   	   if(result.errcode==0){
        	  	   		   ajaxFileUpload(2);
        	  	   	   }
        	       },  
        	       error : function () {  
        	       		return;
        	       }  
           });
		}else{
			ajaxFileUpload(2);
		}
	}
/*	if(objUrl!=null) {
		$("#logoShow img").attr("src", objUrl);
		if(companyPicFlag==1){
			deleteFile(companyPicName,2);
			params ="uid="+$.cookie("jrqUid")+"&user.companyPic="+0+"&sessionId="+$.cookie("sessionId");//0����
			$.ajax({  
				type : 'post',  
				url : 'updateUserInfo.action',  
				dataType : 'json',  
				data :  {"params":params},
				success : function (result) {
					if(result.errcode==0){
						ajaxFileUpload(2);
					}
				},  
				error : function () {  
					return;
				}  
			});
		}else{
			ajaxFileUpload(2);
		}
	}
*/}) ;
function deleteFile(fileName,fileFlag) {
    if(fileFlag==2){
		fileName = companyPicName;
	}
    $.ajax({  
	       type : 'post',  
	       url : 'deleteFile.action',  
	       dataType : 'json',  
	       data :  {"fileName":fileName,"fileFlag":fileFlag},
	  	   success : function (result) {
	  	   	   if(result.errcode==0){
	  	   	   }
	       },  
	       error : function () {  
	       		return;
	       }  
   });
}
function getObjectURL(file) {
	var url = null ; 
	if (window.createObjectURL!=undefined) { // basic
		url = window.createObjectURL(file) ;
	} else if (window.URL!=undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file) ;
	} else if (window.webkitURL!=undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file) ;
	}
	return url ;
}
function ajaxFileUpload(fileFlag) {
    // ��ʼ�ϴ��ļ�ʱ��ʾһ��ͼƬ
    $("#wait_loading").ajaxStart(function() {
        $(this).show();
    // �ļ��ϴ���ɽ�ͼƬ��������
    }).ajaxComplete(function() {
        $(this).hide();
    });
    if(fileFlag==2){
		fileName = companyPicName;
		fileElementId = "logo";
	}
    //var elementIds=["flag"]; //flagΪid��name������
    $.ajaxFileUpload({
        url: 'UploadFile.action', 
        type: 'post',
        data: {"fileName":fileName,"fileFlag":fileFlag},
        dataType : 'text',  //����ֵ���ͣ�һ������Ϊjson��application/json
        //secureuri: false, //һ������Ϊfalse
        fileElementId: fileElementId, // �ϴ��ļ���id��name������
        //elementIds: elementIds, //���ݲ��������
        success: function(result){  
        	result = JSON.parse(result);
            if(result.errcode==0){
            	if(fileFlag==2){
            		//params ="uid="+$.cookie("jrqUid")+"&sessionId="+$.cookie("sessionId")+"&user.companyPic="+result.imgSrc2;
            		url = "saveCompanyInfo.action";
            	}
                $.ajax({  
            	       type : 'post',  
            	       url : url,  
            	       dataType : 'json',  
            	       //data :  {"params":params},
            	       data :  {	params : uidAndSession
			       					+ '&flag=uploadCompanyPic'
			    					+ '&corpid='
			    					+ corpid
			    					+ '&company.logo='
			    					+result.imgSrc2
    					},
            	  	   success : function (result) {
            	  	   	   if(result.errcode==0){
            	  	   		   window.open("./myCompany.jsp","_top");
            	  	   	   }
            	       },  
            	       error : function () {  
            	    	    delayURL("�ϴ�ʧ��,��ˢ��ҳ����ٴ��ϴ���","3","");
            	       		return;
            	       }  
               });
            }else if(result.errcode=="40003"){
            	delayURL("ͼƬ�ϴ�ʧ�ܣ�","3","");
            }
        },
        error: function(result){ 
        	return;
        	//delayURL("ͼƬ�ϴ�ʧ�ܣ�","3","");
        }
    });
    //return false;
}



/*function img_check(obj, action_url, companyId, id) {
	var logo = obj.value;

	this.AllowExt = '.jpg,.gif,.jpeg,.png,.pjpeg';// img format(,.pjpeg)
	this.FileExt = logo.substr(logo.lastIndexOf(".")).toLowerCase();

	if (this.AllowExt != 0 && this.AllowExt.indexOf(this.FileExt) == -1)// judge
	// file
	// format
	{
		errorTips("ֻ֧��jpg��gif��png��jpeg��ʽ���������ϴ�");
	} else {
		$.ajaxFileUpload({
			url : action_url,
			secureuri : false,
			fileElementId : id,
			data : {
				companyId : companyId,
				logo : logo
			},
			dataType : 'text',
			success : function(jsonStr) {
				var result = eval('(' + jsonStr + ')');
				if (result.success) {
					$('#logoShow img').attr("src", ctx + '/' + result.content);
					$('#logoNo').hide();
					$('#logoShow').show();
				} else {
					$('#logo_error').text(result.msg).show();
				}
			}
		});// end of ajax

	}
}

*//*******************************************************************************
 * �ϴ���ƷͼƬ��ʽ��֤ ajax�ύ
 *//*
var productFlag = 1;
function product_check(obj, action_url, imgNo, imgShow, type, imgUrl) {
	if (productFlag == 2) {
		return false;
	}
	productFlag = 2;
	var uploadP = $(obj).parents(".new_product");

	this.AllowExt = '.jpg,.jpeg,.gif,.png,.pjpeg';// img format(,.pjpeg)
	this.FileExt = obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();

	if (this.AllowExt != 0 && this.AllowExt.indexOf(this.FileExt) == -1)// judge
	// file
	// format
	{
		errorTips("ֻ֧��jpg��jpeg��gif��png��ʽ���������ϴ�");
	} else {
		$.ajaxFileUpload({
			url : action_url,
			secureuri : false,
			fileElementId : obj.id,
			data : {
				type : 3
			},
			dataType : 'text',
			success : function(data) {
				productFlag = 1;
				if (data != '') {
					$('.' + imgUrl, uploadP).val(data);
					$('.' + imgShow + ' img', uploadP).attr("src",
							ctx + '/' + data);
					$('.' + imgNo, uploadP).hide();
					$('.' + imgShow, uploadP).show();
				} else {
					productFlag = 1;
					$(".errorTips").click(function() {
						errorTips("�ϴ�ʧ�ܣ��������ϴ�");
					});
				}
			}
		})// end of ajax
	}
}

*//*******************************************************************************
 * �ϴ���ʼ��ͼƬ��ʽ��֤ ajax�ύ
 *//*
var memberFlag = 1;
function member_check(obj, action_url, imgNo, imgShow, type, imgUrl) {
	if (memberFlag == 2) {
		return false;
	}
	memberFlag = 2;
	var uploadP = $(obj).parents(".new_portrait");

	this.AllowExt = '.jpg,.jpeg,.gif,.png,.pjpeg';// img format(,.pjpeg)
	this.FileExt = obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();

	if (this.AllowExt != 0 && this.AllowExt.indexOf(this.FileExt) == -1)// judge
	// file
	// format
	{
		errorTips("ֻ֧��jpg��jpeg��gif��png��ʽ���������ϴ�");
	} else {
		$.ajaxFileUpload({
			url : action_url,
			secureuri : false,
			fileElementId : obj.id,
			data : {
				type : 7
			},
			dataType : 'text',
			success : function(data) {
				memberFlag = 1;
				if (data != '') {
					$('.' + imgUrl, uploadP).val(data);
					$('.' + imgShow + ' img', uploadP).attr("src",
							ctx + '/' + data);
					$('.' + imgNo, uploadP).hide();
					$('.' + imgShow, uploadP).show();
				} else {
					memberFlag = 1;
					$(".errorTips").click(function() {
						errorTips("�ϴ�ʧ�ܣ��������ϴ�");
					});
				}
			}
		})// end of ajax
	}
}*/